package com.forezp.service;

import com.alibaba.fastjson.JSON;
import com.forezp.vo.Order;
import com.google.gson.reflect.TypeToken;
import com.alibaba.fastjson.JSONObject;

import java.lang.reflect.Type;

public class DiffOperationRequest<T> {
    private T newEntity;
    private T oldEntity;
    private Type entityType; // 新增泛型类型的 Type 对象

    // 构造函数
    public DiffOperationRequest() {
        // 获取泛型类型的 Type 对象
        this.entityType = new TypeToken<T>() {}.getType();
    }

    // 解析方法，处理 JSON 参数
    public void parse(String newEntityJson, String oldEntityJson) {
        // 使用 Type 对象进行 JSON 解析
        this.newEntity = JSONObject.parseObject(newEntityJson, this.entityType);
        this.oldEntity = JSONObject.parseObject(oldEntityJson, this.entityType);
    }

    public static void main(String[] args) {
        DiffOperationRequest<Order> logParam =new DiffOperationRequest<>();
        String newStr ="{\"creator\":{\"userId\":9001,\"userName\":\"用户1\"},\"items\":[\"123\",\"bbb\"],\"orderId\":99,\"orderNo\":\"MT0000011\",\"productName\":\"超值优惠红烧肉套餐\",\"purchaseName\":\"张三\"}";
        String oldStr ="{\"creator\":{\"userId\":9002,\"userName\":\"用户2\"},\"items\":[\"123\",\"bbb\"],\"orderId\":99,\"orderNo\":\"MT0000011\",\"productName\":\"超值优惠红烧肉套餐\",\"purchaseName\":\"张三\"}";
        logParam.parse(newStr,oldStr);
        final Order order = JSONObject.parseObject(null, Order.class);

    ;
        System.out.println(1);

    }
}
